﻿{% extends "base_cn.html" %}
{% block title %} -- 我的溜溜 {% endblock %}
{% block content %}

<script type="text/javascript" src="static/gears_init.js"></script>
<script type="text/javascript" src="http://www.google.cn/jsapi?key=ABQIAAAASxuhjqc-j0-xBqPZInKKfhToNW08s6aZzsYvqCmYymrddPgvJxSFfjpuxixLl2WrMuudrwyqAsajsg"></script>
<!--script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAASxuhjqc-j0-xBqPZInKKfhToNW08s6aZzsYvqCmYymrddPgvJxSFfjpuxixLl2WrMuudrwyqAsajsg"></script-->

<script type="text/javascript" src="/static/json2.js"></script>

<script type="text/javascript"> 
//    google.load("maps", "2"); 
    google.load("maps", "2", {"base_domain": "ditu.google.cn"}); 

    var geocoder = null;
    var map = null;

    var lat = null;
    var lon = null;
    var old_overlay = null;


{% if UserInfo.Latitude %}
    lat = {{ UserInfo.Latitude }};
{% endif %}

{% if UserInfo.Longitude %}
    lon = {{ UserInfo.Longitude }};
{% endif %}

    function handleError(positionError)
    {
	alert('获取本地坐标失败: ' + positionError.message);
    }

    function SetLocalPosition(position)
    {
	SetMapToLatAndLon(position.latitude, position.longitude);

	//根据当前坐标获得周围的用户
	OnGetNearbyUser(position.latitude, position.longitude);
    }

    function SetMapToLatAndLon(SetLat, SetLon)
    {
	lat = SetLat;
	lon = SetLon;

	if(null == map)
	{
	    map = new google.maps.Map2(document.getElementById("map_canvas"));
	    map.addControl(new GLargeMapControl());
	    map.addControl(new GMapTypeControl());
	}

	var current_location = new GLatLng(SetLat, SetLon);

	map.setCenter(current_location, 13); 

	var marker = new GMarker(current_location, {title:'我的位置'});
	if(null != old_overlay)
	{
	    map.removeOverlay(old_overlay);
	}

	map.addOverlay(marker);
	old_overlay = marker;

	if(null == geocoder)
	{
	    geocoder = new GClientGeocoder();
	}
	geocoder.getLocations(current_location, ShowAddressAtPage);
    }

    function ShowAddressAtPage(response)
    {
	if(response && response.Status.code == 200)
	{
	    place = response.Placemark[0];
	    document.getElementById("human_readable").innerHTML = place.address;
	}
    }

    function initialize()
    { 
	if(null == lat)
	{
	    var geo = google.gears.factory.create('beta.geolocation');
	    geo.getCurrentPosition(SetLocalPosition, handleError);
	}
	else
	{
	    SetMapToLatAndLon(lat, lon);

	    //根据当前坐标获得周围的用户
	    OnGetNearbyUser(lat, lon);
	}
    }




	if( !window.XMLHttpRequest ) XMLHttpRequest = function()
	{
		try{ return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }catch(e){}
		try{ return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }catch(e){}
		try{ return new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){}
		try{ return new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){}
		throw new Error("Could not find an XMLHttpRequest alternative.");
	};

	function OnGetNearbyUser(Latitude, Longitude)
	{
//		alert(InputStr);
		var req = new XMLHttpRequest();
		req.open('GET', '/nearby_user_rpc?Latitude=' + encodeURIComponent(Latitude) + '&Longitude=' + encodeURIComponent(Longitude), true);

		req.onreadystatechange = function()
		{
			if(req.readyState == 4 && req.status == 200)
			{
			    //alert(req.responseText);
			    var response = null;
			    try
			    {
				response = JSON.parse(req.responseText);
			    }
			    catch (e)
			    {
				response = req.responseText;
			    }
			
			    //添加显示图标
			    for (key in response)
			    {
				LoginName = response[key][0];
	    var UserLocation = new GLatLng(response[key][2], response[key][3]);
	    var UserIcon = new GIcon();
	    UserIcon.image = "/userphoto?item=" + response[key][0]; 
	    //UserIcon.shadow = "/userphoto?item=" + response[key][0];
	    UserIcon.iconSize = new GSize(32, 32);
	    //UserIcon.shadowSize = new GSize(32, 32);
	    UserIcon.iconAnchor = new GPoint(0, 32); 
	    UserIcon.infoWindowAnchor = new GPoint(5, 1); 
	
	    var UserMarker = null;
	    if(response[key][1] != '' && response[key][1] != 'null')
	    {
	        UserMarker = new GMarker(UserLocation, {title:response[key][1], icon:UserIcon});
	        map.addOverlay(UserMarker);
		GEvent.addListener(UserMarker, "mouseover", function() {
			UserMarker.openInfoWindowHtml("<a href='/usershow?item=" + response[key][0] + "'>" + response[key][1] + "</a>");
								});
	    }
	    else
	    {
	        UserMarker = new GMarker(UserLocation, {title:response[key][0], icon:UserIcon});
	        map.addOverlay(UserMarker);
		GEvent.addListener(UserMarker, "mouseover", function() {
			UserMarker.openInfoWindowHtml("<a href='/usershow?item=" + response[key][0] + "'>" + response[key][0] + "</a>");
								});
	    }


			    }

			}
		}
		
		req.send(null);
	}


 
    google.setOnLoadCallback(initialize); 

</script>


  <p><a href="/?language=en-us">English</a></p>

  <table borderColor=#cccccc cellSpacing=0 cellPadding=3 width="100%" bgColor=#ffffff border=2>
    {% if UserName %}
    <tr>
      <td>&nbsp;朋友们的新话题</td>
      <td>
	{% for Item in FriendNewBlogs %}
		<p>
		<a target="_blank" href = "/usershow?item={{ Item.LoginName }}">
		<img src = "/userphoto?item={{ Item.LoginName }}" alt="{{ Item.LoginName }}" width="32px" height="32px" style="float:left;">
		</a>
		<a href = "/blog?tag=user&user={{ Item.LoginName }}&item={{ Item.key }}">{{ Item.Content|escape }}</a>
		</p>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;朋友们的新收藏</td>
      <td>
	{% for Item in FriendNewCollects %}
		<p>
		<a target="_blank" href = "/usershow?item={{ Item.LoginName }}">
		<img src = "/userphoto?item={{ Item.LoginName }}" alt="{{ Item.LoginName }}" width="32px" height="32px" style="float:left;">
		</a>
		<a href = "/collect?tag=user&user={{ Item.LoginName }}&item={{ Item.key }}">{{ Item.Title }}</a>
		</p>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;朋友们的新喜爱</td>
      <td>
	{% for Item in FriendNewLikes %}
		<p>
		<a target="_blank" href = "/usershow?item={{ Item.LoginName }}">
		<img src = "/userphoto?item={{ Item.LoginName }}" alt="{{ Item.LoginName }}" width="32px" height="32px" style="float:left;">
		</a>
		<a href = "/like?tag=user&user={{ Item.LoginName }}&item={{ Item.key }}">{{ Item.Title }}</a>
		</p>
	{% endfor %}
      </td>
    </tr>
    {% endif %}

    <tr>
      <td>&nbsp;最热话题&nbsp;<a href = "/rss_hot_microblog.xml"><img src = "/images/rss.png" /></a></td>
      <td>
	{% for BlogItem in HotBlogs %}
		<a href = "/blog?tag=syshot&item={{ BlogItem.key }}"><b>{{ BlogItem.Content|escape|truncatehanzi:"10" }}</b></a>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;最新话题&nbsp;<a href = "/rss_new_microblog.xml"><img src = "/images/rss.png" /></a></td>
      <td>
	{% for BlogItem in NewBlogs %}
		<a href = "/blog?tag=sysnew&item={{ BlogItem.key }}"><b>{{ BlogItem.Content|escape|truncatehanzi:"10" }}</b></a>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;最热收藏&nbsp;<a href = "/rss_hot_collect.xml"><img src = "/images/rss.png" /></a></td>
      <td>
	{% for Item in HotCollects %}
		<a href = "/collect?tag=syshot&item={{ Item.key }}"><b>{{ Item.Title }}</b></a>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;最新收藏&nbsp;<a href = "/rss_new_collect.xml"><img src = "/images/rss.png" /></a></td>
      <td>
	{% for Item in NewCollects %}
		<a href = "/collect?tag=sysnew&item={{ Item.key }}"><b>{{ Item.Title }}</b></a>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;最受大家欢迎的&nbsp;<a href = "/rss_hot_like.xml"><img src = "/images/rss.png" /></td>
      <td>
	{% for Item in HotLikes %}
		<a href = "/like?tag=syshot&item={{ Item.key }}"><b>{{ Item.Title }}</b></a>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;最新大家喜爱的&nbsp;<a href = "/rss_new_like.xml"><img src = "/images/rss.png" /></td>
      <td>
	{% for Item in NewLikes %}
		<a href = "/like?tag=sysnew&item={{ Item.key }}"><b>{{ Item.Title }}</b></a>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;最活跃用户</td>
      <td>
	<table cellPadding=0 bgColor=#ffffff border=0>
	  <tr>
	    {% for UserItem in HotUsers %}
		<td align="center">
		<a target="_blank" href = "/usershow?item={{ UserItem.LoginName }}">
		    {% if UserItem.HavePhoto %}
			<img src = "/userphoto?item={{ UserItem.LoginName }}" width="32px" height="32px">
		    {% else %}
			<img src = "/images/defaultphoto.jpg" width="32px" height="32px">
		    {% endif %}
		</a>
		</td>

		<td>&nbsp;</td>
	    {% endfor %}
	  </tr>

	  <tr>
	    {% for UserItem in HotUsers %}
		<td align="center">
		  <a target="_blank" href = "/usershow?item={{ UserItem.LoginName }}"><b>
		    {% ifequal UserItem.NickName '' %}
		  	{{ UserItem.LoginName }}
		    {% else %}
		  	{{ UserItem.NickName }}
		    {% endifequal %}
		  </b></a>
		</td>

		<td>&nbsp;</td>
	    {% endfor %}
	  </tr>
	</table>
      </td>
    </tr>

    <tr>
      <td>&nbsp;新加入用户</td>
      <td>
	<table cellPadding=0 bgColor=#ffffff border=0>
	  <tr>
	    {% for UserItem in NewUsers %}
		<td align="center">
		<a target="_blank" href = "/usershow?item={{ UserItem.LoginName }}">
		    {% if UserItem.HavePhoto %}
			<img src = "/userphoto?item={{ UserItem.LoginName }}" width="32px" height="32px">
		    {% else %}
			<img src = "/images/defaultphoto.jpg" width="32px" height="32px">
		    {% endif %}
		</a>
		</td>

		<td>&nbsp;</td>
	    {% endfor %}
	  </tr>

	  <tr>
	    {% for UserItem in NewUsers %}
		<td align="center">
		  <a target="_blank" href = "/usershow?item={{ UserItem.LoginName }}"><b>
		    {% ifequal UserItem.NickName '' %}
		  	{{ UserItem.LoginName }}
		    {% else %}
		  	{{ UserItem.NickName }}
		    {% endifequal %}
		  </b></a>
		</td>

		<td>&nbsp;</td>
	    {% endfor %}
	  </tr>
	</table>
      </td>
    </tr>

    <tr>
      <td>&nbsp;最受欢迎的工具</td>
      <td>
	{% for ToolItem in HotTools %}
		<a href = "/tool?tag=syshot&item={{ ToolItem.key }}"><b>{{ ToolItem.Title }}</b></a>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;天涯头条&nbsp;<a href = "/rss_tianya_top.xml"><img src = "/images/rss.png" /></td>
      <td>
	{% for Item in TianYaTops.items %}
		<a href = "{{ Item.0 }}"><b>{{ Item.1 }}</b></a><br>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;天涯热点&nbsp;<a href = "/rss_tianya_hot.xml"><img src = "/images/rss.png" /></td>
      <td>
	{% for Item in TianYaHots.items %}
		<a href = "{{ Item.0 }}"><b>{{ Item.1 }}</b></a><br>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;最受欢迎的工具</td>
      <td>
	{% for ToolItem in HotTools %}
		<a href = "/tool?tag=syshot&item={{ ToolItem.key }}"><b>{{ ToolItem.Title }}</b></a>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;附近的溜溜网用户</td>
      <td>
		<div id="map_canvas" style="width: 500px; height: 300px"></div>
		<div id="human_readable"></div>
      </td>
    </tr>

  </table>




{% endblock %}